<template>
  <div id="lineMain" style="width: 100%; height: 345px"></div>
</template>

<script>
import { MemberDataGraph } from '@/api/home/workplace'
// 引入 echarts 核心模块，核心模块提供了 echarts 使用必须要的接口。
import * as echarts from 'echarts/core'
// 引入柱状图图表，图表后缀都为 Chart
import { LineChart } from 'echarts/charts'
// 引入提示框，标题，直角坐标系，数据集，内置数据转换器组件，组件后缀都为 Component
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent,
  LegendComponent,
} from 'echarts/components'
// 标签自动布局、全局过渡动画等特性
import { LabelLayout, UniversalTransition } from 'echarts/features'
// 引入 Canvas 渲染器，注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers'

// 注册必须的组件
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent,
  LabelLayout,
  UniversalTransition,
  CanvasRenderer,
  LegendComponent,
  LineChart,
])
export default {
  data() {
    return {}
  },
  methods: {},
  async mounted() {
    let res = await MemberDataGraph()
    var myChart = echarts.init(document.getElementById('lineMain'))
    myChart.setOption({
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: res.data.monthList,
      },
      yAxis: {
        type: 'value',
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow',
        },
      },
      legend: {
        left: '9%',
        itemGap: 40,
        data: ['会员总数', '临期会员', '过期会员', '退会会员'],
      },
      series: [
        {
          name: '会员总数',
          data: res.data.memberNumList,
          type: 'line',
          smooth: true,
          areaStyle: {
            opacity: 0.5,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: 'rgba(84, 112, 198, 0.5)',
              },
              {
                offset: 1,
                color: 'rgba(84, 112, 198, 0)',
              },
            ]),
          },
        },
        {
          name: '退会会员',
          data: res.data.retiredMemberNumList,
          type: 'line',
          smooth: true,
          areaStyle: {
            opacity: 0.5,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: 'rgba(128, 255, 165, 0.5)',
              },
              {
                offset: 1,
                color: 'rgba(128, 255, 165, 0)',
              },
            ]),
          },
        },
      ],
    })
  },
}
</script>

<style lang="less" scoped></style>
